package com.photoeditor.demo.ui.widget.image.compose;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * 这个主要是增加了一个Touch的回调
 */
public class SelectColorView extends View {

    private ICanvasEditListener mIListener;

    public SelectColorView(Context context) {
        super(context);
    }

    public SelectColorView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SelectColorView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (mIListener != null) {
                mIListener.onTouchDown(event.getRawX());
            }
            return true;
        } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
            if (mIListener != null) {
                mIListener.onTouchMove(event.getRawX());
            }
        } else {
            if (mIListener != null) {
                mIListener.onTouchUp(event.getRawX());
            }
        }
        return super.onTouchEvent(event);
    }

    public void setListener(ICanvasEditListener listener) {
        mIListener = listener;
    }
}
